package com.ellricky.teacher.ui.mycourse.experience

import android.view.View
import com.andr.common.http.callback.JOCallback
import com.andr.common.ui.activity.BaseToolBarActivity
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.util.EmptyUtil
import com.andr.common.util.ToastUtil
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.http.HttpUtils
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.teacher.API_EXPERIENCE_SUMUP_SAVE
import com.ellricky.teacher.R
import kotlinx.android.synthetic.main.tc_activity_experience_add.*
import org.json.JSONObject

class ExperienceAddActivity : BaseToolBarActivity<Void, BasePresenter<Void>>(){

    override fun getContentLayout(): Int {
        return R.layout.tc_activity_experience_add
    }

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = getString(R.string.tc_experience_sum_up)

        etCourseControl.setKeySize(18f)
        etCommunicate.setKeySize(18f)
        etSign.setKeySize(18f)
        etWorkResult.setKeySize(18f)

        btnSubmit.setOnClickListener(this)
    }


    override fun onClickView(v: View?) {
        super.onClickView(v)
        when (v) {
            btnSubmit -> postSubmit()
        }
    }

    private fun postSubmit() {
        val classInfo = etCourseControl.value
        if (EmptyUtil.isEmpty(classInfo)) {
            ToastUtil.show(this, R.string.tc_course_control_tip)
            return
        }

        val communicate = etCommunicate.value
        if (EmptyUtil.isEmpty(communicate)) {
            ToastUtil.show(this, R.string.tc_communicate_tip)
            return
        }

        val formResult = etSign.value
        if (EmptyUtil.isEmpty(formResult)) {
            ToastUtil.show(this, R.string.tc_if_sign_tip)
            return
        }

        val workResult = etWorkResult.value
        if (EmptyUtil.isEmpty(workResult)) {
            ToastUtil.show(this, R.string.tc_work_result_tip)
            return
        }

        val paramMap = mutableMapOf<String, Any>(
                "classInfo" to classInfo,
                "communicate" to communicate,
                "formResult" to formResult,
                "workResult" to workResult)

        val url = EAppUtil.getApiHost() + API_EXPERIENCE_SUMUP_SAVE
        HttpUtils.getInstance().post(url, paramMap, object : JOCallback(this) {
            override fun onSuccess(dataJO: JSONObject?, msg: String?) {
                setResult(BaseConstant.RESULT_CODE_ADD)
                finish()
            }
        })

    }
}

